package com.yc.yyds.servlet;

import com.google.gson.Gson;
import com.yc.yyds.Bean.Result;
import com.yc.yyds.biz.BizException;
import com.yc.yyds.biz.QueryShowListBiz;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "BuyShowMoviesServlet", value = "/BuyShowMoviesServlet.s")
public class BuyShowMoviesServlet extends HttpServlet {
    QueryShowListBiz biz = new QueryShowListBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String movieid = request.getParameter("movieid");
        String starttime = request.getParameter("starttime");
        starttime = starttime.replace("月","-");
        starttime = starttime.replace("日","");
        System.out.println("starttime = " + starttime);
        Result result;
        try {
            List<Map<String, Object>> data = biz.QueryShowListMovies(movieid,starttime);
            result = new Result(1,"查询成功",data);
            String json = new Gson().toJson(result);
            response.getWriter().append(json);
        } catch (BizException e) {
            e.printStackTrace();
            result = new Result(0,e.getMessage(),null);
            String json = new Gson().toJson(result);
            response.getWriter().append(json);
        } catch (Exception e2){
            e2.printStackTrace();
            result = new Result(0,"业务繁忙",null);
            String json = new Gson().toJson(result);
            response.getWriter().append(json);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
